/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgPlayerAvatarFrame
    {
        private readonly Dictionary<int, CfgPlayerAvatarFrame> _dataMap;
        private readonly List<CfgPlayerAvatarFrame> _dataList;


        public TbCfgPlayerAvatarFrame(ByteBuf _buf)
        {
            //first read common data
            _TbCommonPlayerAvatarFrame _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonPlayerAvatarFrame(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgPlayerAvatarFrame>(size * 3 / 2);
            _dataList = new List<CfgPlayerAvatarFrame>(size);

            for (int i = 0; i < size; i++)
            {
                CfgPlayerAvatarFrame _v;
                _v = CfgPlayerAvatarFrame.DeserializeCfgPlayerAvatarFrame(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgPlayerAvatarFrame> DataMap => _dataMap;
        public IReadOnlyList<CfgPlayerAvatarFrame> DataList => _dataList;

        public CfgPlayerAvatarFrame Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgPlayerAvatarFrame] config not found,id:" + key.ToString());

            return null;
        }

        public CfgPlayerAvatarFrame GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "playeravatarframe";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgPlayerAvatarFrame LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgPlayerAvatarFrame(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgPlayerAvatarFrame
    {
        private CfgPlayerAvatarFrame(ByteBuf _buf, _TbCommonPlayerAvatarFrame _commonData)
        {
            Id = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            Desc = TableCenter.GetI18NText(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; Prefab = _commonData._field0[dataIndex]; }
            IsLock = _buf.ReadBool();
            IsLockShow = _buf.ReadBool();
            LimitiedDuration = _buf.ReadInt();
            Sort = _buf.ReadInt();
            LockDesc = TableCenter.GetI18NText(_buf.ReadInt());

            PostInit();
        }

        internal static CfgPlayerAvatarFrame DeserializeCfgPlayerAvatarFrame(ByteBuf _buf, _TbCommonPlayerAvatarFrame _commonData)
        {
            return new CfgPlayerAvatarFrame(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 名字
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Desc { get; private set; }
        /// <summary>
        /// 预设资源
        /// </summary>
        public string Prefab { get; private set; }
        /// <summary>
        /// 是否需要解锁
        /// </summary>
        public bool IsLock { get; private set; }
        /// <summary>
        /// 未解锁时是否显示
        /// </summary>
        public bool IsLockShow { get; private set; }
        /// <summary>
        /// 限时激活时间(秒)
        /// </summary>
        public int LimitiedDuration { get; private set; }
        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; private set; }
        /// <summary>
        /// 锁定描述
        /// </summary>
        public string LockDesc { get; private set; }

        /// <summary>
        /// Prefab 全路径
        /// </summary>
        public string Prefab_fullPath => $"Res/03_Prefabs/UI/AvatarFrame/{Prefab}";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonPlayerAvatarFrame
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal _TbCommonPlayerAvatarFrame(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
